﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data.SqlClient;

namespace DAO
{
    public class QUYENHANDAO
    {
        ///CỦA AI THÌ TỰ ĐÓNG KHUNG VÀO. TRÁNH XÓA NHẦM CODE
        /////////////////CỦA LINH///////////////////
        public List<QUYENHANDTO> LayDSQH(NHANVIENDTO NVDTO)
        {
            SqlConnection conn = DataProvider.ConnectDB();

            SqlCommand command = new SqlCommand( "LINH03_LAYDSQH", conn);
            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add("@MaCV", System.Data.SqlDbType.Int);
            command.Parameters["@MaCV"].Value = NVDTO.MaCV;
            
            SqlDataReader reader = command.ExecuteReader();
            List<QUYENHANDTO> ds = new List<QUYENHANDTO>();
            while(reader.Read())
            {
                QUYENHANDTO QHDTO = new QUYENHANDTO();
                QHDTO.QH = reader.GetInt32(0);
                ds.Add(QHDTO);
            }

            conn.Close();
            return ds;
        }
        ///////////////////////////////////////
        public List<QUYENHANDTO> LayDSQH(CHUCVUDTO CvDTO)
        {
            SqlConnection conn = DataProvider.ConnectDB();

            SqlCommand command = new SqlCommand("LINH03_LAYDSQH", conn);
            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add("@MaCV", System.Data.SqlDbType.Int);
            command.Parameters["@MaCV"].Value = CvDTO.MaCV;

            SqlDataReader reader = command.ExecuteReader();
            List<QUYENHANDTO> ds = new List<QUYENHANDTO>();
            while (reader.Read())
            {
                QUYENHANDTO QHDTO = new QUYENHANDTO();
                QHDTO.QH = reader.GetInt32(0);
                ds.Add(QHDTO);
            }

            conn.Close();
            return ds;
        }
        public void ThemQH(QUYENHANDTO QhDTO, int flag)
        {
            SqlConnection conn = DataProvider.ConnectDB();

            SqlCommand command = new SqlCommand("themQH", conn);
            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add("@MaCV", System.Data.SqlDbType.Int);
            command.Parameters["@MaCV"].Value = QhDTO.MaCV;
            command.Parameters.Add("@QH", System.Data.SqlDbType.Int);
            command.Parameters["@QH"].Value = QhDTO.QH;
            command.Parameters.Add("@f", System.Data.SqlDbType.Int);
            command.Parameters["@f"].Value = flag;

            command.ExecuteNonQuery();
            conn.Close();
        }
    }
}
